package com.android.component;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class AnimationTest extends Activity implements OnClickListener {

    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.animation_test);

        iv = (ImageView) findViewById(R.id.iv);

        findViewById(R.id.rotate).setOnClickListener(this);
        findViewById(R.id.transmit).setOnClickListener(this);
        findViewById(R.id.scale).setOnClickListener(this);
        findViewById(R.id.alpha).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        Animation animation = null;
        if (v.getId() == R.id.rotate) {
            animation = new RotateAnimation(0, -90, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setDuration(5000);
            animation.setZAdjustment(Animation.ZORDER_NORMAL);

        } else if (v.getId() == R.id.transmit) {
            animation = new TranslateAnimation(0, 120, 0, 120);
            animation.setDuration(5000); //设置持续时间5秒
        } else if (v.getId() == R.id.scale) {
            animation = new ScaleAnimation(0.0f, 5f, 0.0f, 5f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setDuration(5000); //设置持续时间5秒
        } else if (v.getId() == R.id.alpha) {
            animation = new AlphaAnimation(0.1f, 1.0f);
            animation.setDuration(5000); //设置持续时间5秒
        }

        animation.setRepeatCount(5);

        Drawable drawable = iv.getDrawable();

        v.startAnimation(animation);
    }
}
